package registnet.records.grade.source;

import java.util.List;

import registnet.records.Curriculum;
import registnet.records.DefaultCourse;
import registnet.records.Grade;
import registnet.records.Section;
import registnet.records.Student;
import registnet.records.grade.CompletionGradeSheet;
import registnet.records.source.DegreeProgramSource;


public class CompletionGradeSheetSource {

	private CompletionGradeSheet completionGradeSheet;
	
	public CompletionGradeSheetSource(){
		this.load();
	}

	public void load(){
		registnet.dao.GradePeer gp = new registnet.dao.GradePeer();
		List<registnet.dao.Grade> grades = gp.getGradesForCompletion();
		this.completionGradeSheet = new CompletionGradeSheet();
		
		for(int i=0; i<grades.size(); i++){
			try{
				registnet.dao.Student DAOStudent = grades.get(i).getStudent();
				Student student = new Student(DAOStudent.getStudentNumber());
				student.setSex(DAOStudent.getSex());
				student.setCurriculum(new Curriculum(DAOStudent.getCurriculum().getCurriculumCode()));
				student.getCurriculum().setDegreeProgram(new DegreeProgramSource(DAOStudent.getCurriculum().getDegreeCourse().getDegreeCode()).getDegreeProgram());
				student.setFirstName(DAOStudent.getFirstName());
				student.setMiddleName(DAOStudent.getMiddleName());
				student.setLastName(DAOStudent.getLastName());
				registnet.dao.Grade DAOGrade = grades.get(i);
				Grade grade = new Grade();
				grade.setStudent(student);
				grade.setCourse(new DefaultCourse(DAOGrade.getCourse().getCourseCode()));
				grade.setSection(new Section(DAOGrade.getSectionName()));
				grade.setYear(DAOGrade.getAcademicYear());
				grade.setSemester(DAOGrade.getSemester());
				this.completionGradeSheet.addGrade(grade);
			}catch(Exception e){e.printStackTrace();}
		}
	}
	
	public CompletionGradeSheet getCompletionGradeSheet(){
		return this.completionGradeSheet;
	}
}
